close all;

aanmaakmodel
sim('model2');

figure;
subplot(2,3,1)
plot(simout.time, simout.signals.values(:,1),'LineWidth',1.5);
ylabel('x')
hold on
plot([simout.time(1) simout.time(end)],[0 0], 'k--')
hold off
xlabel('s');
subplot(2,3,2)
plot(simout.time, simout.signals.values(:,2),'LineWidth',1.5);
ylabel('theta');
hold on
plot([simout.time(1) simout.time(end)],[0 0], 'k--')
hold off
xlabel('s');
subplot(2,3,3)
plot(voltage.time, voltage.signals.values(:,1),'LineWidth',1);
ylabel('Input voltage');
xlabel('s');

Q=diag([1000 8000 0 0]);
R=0.2;
[K,S,e]=lqr(A,B,Q,R);
sim('model2');
subplot(2,3,4)
plot(simout.time, simout.signals.values(:,1),'LineWidth',1.5);
ylabel('x')
hold on
plot([simout.time(1) simout.time(end)],[0 0], 'k--')
hold off
xlabel('s');
subplot(2,3,5)
plot(simout.time, simout.signals.values(:,2),'LineWidth',1.5);
ylabel('theta');
hold on
plot([simout.time(1) simout.time(end)],[0 0], 'k--')
hold off
xlabel('s');
subplot(2,3,6)
plot(voltage.time, voltage.signals.values(:,1),'LineWidth',1);
ylabel('Input voltage');
xlabel('s');
%%
matlab2tikz('../verslag/img/differentQR.tikz', 'height', '\figureheight', 'width', '\figurewidth' );